package com.tanhua.server.controller;

import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 注册或登录时，发送验证码
     *
     * ResponseEntity spring 封装统一返回 结果
     * 要与前端达成一致，yapi
     * @param paramMap
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String,String> paramMap){
        // 调用业务
        userService.sendValidateCode(paramMap);
        // 响应结果
        // .ok = ok().body(null); body为null，没有响应数据给前端
        // ok() 响应状态码为200 代表成功
        return ResponseEntity.ok(null);
    }

    /**
     * 注册登录 验证码校验
     * @param paramMap
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> paramMap){
        Map<String, Object> resultMap = userService.loginVerification(paramMap);
        return ResponseEntity.ok(resultMap);
    }
}
